package com.yunji.coffee.entity.dto;

import com.yunji.cabinet.cache.CabinetCache;
import com.yunji.cabinet.context.calculate.CabinetCalculate;
import com.yunji.cabinet.domain.ContainerCell;
import com.yunji.common.model.cache.CabinetCacheDTO;
import com.yunji.product.cache.ProductCache;
import lombok.Data;
import org.apache.commons.compress.utils.Lists;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2025/1/24 15:24
 * @description : TODO
 **/
@Data
//@JsonTypeInfo(
//        use = JsonTypeInfo.Id.NAME,   // 让 `DeviceInfoDTO` 只使用 `@type`
//        include = JsonTypeInfo.As.PROPERTY,
//        property = "@type"
//)
public class WipeDeviceInfoDTO extends DeviceInfoDTO implements ICommonDeviceInfo, Serializable {
    private static final long serialVersionUID = 1L;

    private Integer inLimitStatus; //  是否完全进仓
    private Integer outLimitStatus; //  是否完全出仓
    private Integer distance;  // 距离
    private Integer tissueStatus; // 是否有货

    @Override
    public List<ICommonDeviceDetail> getDetailList() {
        List<ICommonDeviceDetail> a = Lists.newArrayList();
        a.add(new ICommonDeviceDetail() {
            @Override
            public Integer getOrdinal() {
                return 1;
            }

            @Override
            public Integer getDistance() {
                return WipeDeviceInfoDTO.this.getDistance();
            }

            @Override
            public Integer getQuantityAvailable() {
                return WipeDeviceInfoDTO.this.getTissueStatus();
            }

            @Override
            public DeviceCellDetailDTO getCellDetail() {
                CabinetCacheDTO cabinet = CabinetCache.getCabinet(WipeDeviceInfoDTO.this.getImei());
                ContainerCell cell = CabinetCache.getCellList(cabinet.getContainerId()).get(0);
                BigDecimal bottomHeight = ProductCache.getBottomHeight(cell.getProductId());
                return CabinetCalculate.getEventQuantity(cabinet,cell,WipeDeviceInfoDTO.this.distance-bottomHeight.intValue());
            }

            @Override
            public Integer getMotorStatus() {
                return 1;
            }
        });
        return a;
    }
}
